<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/META-INF/math.tld" prefix="math" %>

<c:set var="test" value="${history.test}"></c:set>

<h3>${test.name}</h3>
<p><b>Mô tả:</b> ${test.description}</p>
<p><b>Thời gian cho phép:</b> ${test.time} phút</p>
<p><b>Thời gian làm:</b> ${math:floor(history.time/60)} phút 
	<c:if test="${history.time%60 != 0}">${history.time%60} giây</c:if> 
</p>

<c:set var="type" value="${test.type=='radio' ? 'radio' : 'checkbox'}"></c:set>
<c:set var="i" value="0"></c:set>
<c:forEach items="${test.questions}" var="question">
	<div>
		<p><b><a href="?action=question.view&id=${question.id}">Câu ${i+1}</a></b>
		</p>
		${question.content}
		<ul style="list-style:none">
		
		<c:set var="j" value="0"></c:set>
		<c:forEach items="${question.answers}" var="answer">
			<!-- kiểm tra câu trả lời có được chọn hay không -->
			<c:set var="choosed" value="false"></c:set>
			<c:forEach items="${history.answers[question.id]}" var="anId">
				<c:if test="${anId == answer.id}">
					<c:set var="choosed" value="true"></c:set>
				</c:if>
			</c:forEach>
			
			<li>
				<label ${answer.correct ? "style='color:red'" : ""}>
					<input type="${type}" ${choosed ? "checked" : ""} 
						disabled></input>
					${answer.content}
				</label>
				<c:if test="${choosed}">
					<c:choose>
						<c:when test="${answer.correct}">
							<i>Đúng :-)</i>
						</c:when>
						<c:when test="${!answer.correct}">
							<i>Sai :-(</i>
						</c:when>
					</c:choose>
				</c:if>
			</li>
			<c:set var="j" value="${j+1}"></c:set>	
		</c:forEach>
		</ul>
	</div>
	<c:set var="i" value="${i+1}"></c:set>
</c:forEach>
